﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace 桌面视频录制
{
    [Serializable]
    public class DrawColumn: DrawRectangle
    {
        public DrawColumn(Point point)
            : base(point){ }
        public override void Draw(Graphics g)
        {
            if (width <= 0 || height <= 4)
                return;
            Pen pen = new Pen(this.penColor, this.penWidth);
            PointF p1 = GetMiddlePoint(leftUpPoint, leftDownPoint);
            PointF p2 = GetMiddlePoint(leftUpPoint, GetMiddlePoint(leftUpPoint, p1));
            PointF p3 = GetMiddlePoint(leftDownPoint, GetMiddlePoint(leftDownPoint, p1));
            g.DrawLine(pen, p2, p3);
            PointF p4 = GetMiddlePoint(rightUpPoint, rightDownPoint);
            PointF p5 = GetMiddlePoint(rightUpPoint, GetMiddlePoint(rightUpPoint, p4));
            PointF p6 = GetMiddlePoint(rightDownPoint, GetMiddlePoint(rightDownPoint, p4));
            g.DrawLine(pen, p5, p6);

            Matrix matrix = new Matrix();
            matrix.RotateAt((float)(angle * 180 / Math.PI), leftUpPoint);
            g.Transform = matrix;
            g.DrawEllipse(pen, leftUpPoint.X, leftUpPoint.Y, width, height / 4);
            matrix.Reset();
            PointF temp = GetMiddlePoint(leftDownPoint, p1);
            matrix.RotateAt((float)(angle * 180 / Math.PI), temp);
            g.Transform = matrix;
            g.DrawArc(pen, temp.X, temp.Y, width, height / 4, 0, 180);
            pen.DashStyle = DashStyle.Dot;
            pen.DashPattern = new float[] { 5.0f, 5.0f };
            g.DrawArc(pen, temp.X, temp.Y, width, height / 4, 0, -180);
            g.ResetTransform();
            g.DrawLine(pen, p2, p5);
            g.DrawLine(pen, p3, p6);
            g.DrawLine(pen, GetMiddlePoint(p2, p5), GetMiddlePoint(p3, p6));
            matrix.Dispose();
            pen.Dispose();
        }
        public override string ToString()
        {
            string printMsg = "[圆柱(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + ")]->[ID:" + this.Id + "]";
            return printMsg;
        }
        public override string GetDrawObjectMsg()
        {
            string drawObjectMsg = "圆柱->起始位置(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + "),宽高(" + this.width + "," + this.height + "),偏移角度:" + ((int)(angle * 180 / Math.PI)) + "°";
            return drawObjectMsg;
        }
    }
}
